<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="../assets/js/vue.js"></script>
    <link rel="stylesheet" href="../assets/css/index.css"/>
</head>
<body>
<h1>Vue.directive自定义指令(学angular的，尽量不用)</h1>
<hr>
<div id="app">
    <div v-wos.color.fontSize="color" id="aaa">
        {{num}}

    </div>
    <p>
        <button @click="jia">+</button>
    </p>
</div>
<button onclick="xiezai()">解绑</button>
解绑和删除元素是两回事,只是不再被控制

<script>
    function xiezai() {
        vm.$destroy()
    }
    Vue.directive('wos', {
            bind: function (el, binding, vnode) {//被绑定
                //el就是wos那个标签
                console.log('1.bind');
//                var s=JSON.stringify;
//                el.innerHTML=
//                    'name:'+s(binding.name)+'<br/>'+
//                    'value:'+s(binding.value)+'<br/>'+
//                    'expression:'+s(binding.expression)+' 绑定的名称<br/>'+
//                    'argument:'+s(binding.arg)+'<br/>'+
//                    'modifiers:'+s(binding.modifiers)+'<br/>'+
//                    'vnode keys:'+Object.keys(vnode).join(', ')+'<br/>';
                el.style='color:'+binding.value

            },
            inserted: function () {//绑定到节点,加载完成
                console.log('2.inserted');
            },
            update: function (el, binding, vnode) {//组件更新开始
                console.log('3.update');
                el.style='color:green'
            },
            componentUpdated: function () {//组件更新完成
                console.log('4.componentUpdated');
            },
            unbind: function () {//解绑
                console.log('5.unbind');
            },
        }
    );

    var vm = new Vue({
        el: '#app',
        data: {
            num: 10,
            color: 'red'
        },
        methods: {
            jia: function () {
                return this.num++
            }
        }
    })
</script>
</body>
</html>